home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Visual Basic new SourceCode and Projects / Adventure game / Calc.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-05-20  |  10.9 KB  |  361 lines

  1. VERSION 5.00
  2. Begin VB.Form Calculator 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "AGC Calculator"
  5.    ClientHeight    =   2625
  6.    ClientLeft      =   2580
  7.    ClientTop       =   1485
  8.    ClientWidth     =   2880
  9.    ClipControls    =   0   'False
  10.    BeginProperty Font 
  11.       Name            =   "System"
  12.       Size            =   9.75
  13.       Charset         =   0
  14.       Weight          =   700
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    Icon            =   "Calc.frx":0000
  20.    LinkMode        =   1  'Source
  21.    LinkTopic       =   "Form1"
  22.    MaxButton       =   0   'False
  23.    MDIChild        =   -1  'True
  24.    MinButton       =   0   'False
  25.    PaletteMode     =   1  'UseZOrder
  26.    ScaleHeight     =   2625
  27.    ScaleWidth      =   2880
  28.    ShowInTaskbar   =   0   'False
  29.    WhatsThisHelp   =   -1  'True
  30.    Begin VB.CommandButton Number 
  31.       Caption         =   "7"
  32.       Height          =   480
  33.       Index           =   7
  34.       Left            =   120
  35.       TabIndex        =   7
  36.       ToolTipText     =   "7"
  37.       Top             =   600
  38.       Width           =   480
  39.    End
  40.    Begin VB.CommandButton Number 
  41.       Caption         =   "8"
  42.       Height          =   480
  43.       Index           =   8
  44.       Left            =   600
  45.       TabIndex        =   8
  46.       ToolTipText     =   "8"
  47.       Top             =   600
  48.       Width           =   480
  49.    End
  50.    Begin VB.CommandButton Number 
  51.       Caption         =   "9"
  52.       Height          =   480
  53.       Index           =   9
  54.       Left            =   1080
  55.       TabIndex        =   9
  56.       ToolTipText     =   "9"
  57.       Top             =   600
  58.       Width           =   480
  59.    End
  60.    Begin VB.CommandButton Cancel 
  61.       Caption         =   "C"
  62.       Height          =   480
  63.       Left            =   1800
  64.       TabIndex        =   10
  65.       ToolTipText     =   "Clear"
  66.       Top             =   600
  67.       Width           =   480
  68.    End
  69.    Begin VB.CommandButton CancelEntry 
  70.       Caption         =   "CE"
  71.       Height          =   480
  72.       Left            =   2280
  73.       TabIndex        =   11
  74.       ToolTipText     =   "Cancel Entry"
  75.       Top             =   600
  76.       Width           =   480
  77.    End
  78.    Begin VB.CommandButton Number 
  79.       Caption         =   "4"
  80.       Height          =   480
  81.       Index           =   4
  82.       Left            =   120
  83.       TabIndex        =   4
  84.       ToolTipText     =   "4"
  85.       Top             =   1080
  86.       Width           =   480
  87.    End
  88.    Begin VB.CommandButton Number 
  89.       Caption         =   "5"
  90.       Height          =   480
  91.       Index           =   5
  92.       Left            =   600
  93.       TabIndex        =   5
  94.       ToolTipText     =   "5"
  95.       Top             =   1080
  96.       Width           =   480
  97.    End
  98.    Begin VB.CommandButton Number 
  99.       Caption         =   "6"
  100.       Height          =   480
  101.       Index           =   6
  102.       Left            =   1080
  103.       TabIndex        =   6
  104.       ToolTipText     =   "6"
  105.       Top             =   1080
  106.       Width           =   480
  107.    End
  108.    Begin VB.CommandButton Operator 
  109.       Caption         =   "+"
  110.       Height          =   480
  111.       Index           =   1
  112.       Left            =   1800
  113.       TabIndex        =   12
  114.       ToolTipText     =   "Add"
  115.       Top             =   1080
  116.       Width           =   480
  117.    End
  118.    Begin VB.CommandButton Operator 
  119.       Caption         =   "-"
  120.       Height          =   480
  121.       Index           =   3
  122.       Left            =   2280
  123.       TabIndex        =   13
  124.       ToolTipText     =   "Subtract"
  125.       Top             =   1080
  126.       Width           =   480
  127.    End
  128.    Begin VB.CommandButton Number 
  129.       Caption         =   "1"
  130.       Height          =   480
  131.       Index           =   1
  132.       Left            =   120
  133.       TabIndex        =   1
  134.       ToolTipText     =   "1"
  135.       Top             =   1560
  136.       Width           =   480
  137.    End
  138.    Begin VB.CommandButton Number 
  139.       Caption         =   "2"
  140.       Height          =   480
  141.       Index           =   2
  142.       Left            =   600
  143.       TabIndex        =   2
  144.       ToolTipText     =   "2"
  145.       Top             =   1560
  146.       Width           =   480
  147.    End
  148.    Begin VB.CommandButton Number 
  149.       Caption         =   "3"
  150.       Height          =   480
  151.       Index           =   3
  152.       Left            =   1080
  153.       TabIndex        =   3
  154.       ToolTipText     =   "3"
  155.       Top             =   1560
  156.       Width           =   480
  157.    End
  158.    Begin VB.CommandButton Operator 
  159.       Caption         =   "X"
  160.       Height          =   480
  161.       Index           =   2
  162.       Left            =   1800
  163.       TabIndex        =   14
  164.       ToolTipText     =   "Multiply"
  165.       Top             =   1560
  166.       Width           =   480
  167.    End
  168.    Begin VB.CommandButton Operator 
  169.       Caption         =   "/"
  170.       Height          =   480
  171.       Index           =   0
  172.       Left            =   2280
  173.       TabIndex        =   15
  174.       ToolTipText     =   "Divide"
  175.       Top             =   1560
  176.       Width           =   480
  177.    End
  178.    Begin VB.CommandButton Number 
  179.       Caption         =   "0"
  180.       Height          =   480
  181.       Index           =   0
  182.       Left            =   120
  183.       TabIndex        =   0
  184.       ToolTipText     =   "0"
  185.       Top             =   2040
  186.       Width           =   960
  187.    End
  188.    Begin VB.CommandButton Decimal 
  189.       Caption         =   "."
  190.       Height          =   480
  191.       Left            =   1080
  192.       TabIndex        =   18
  193.       ToolTipText     =   "Decimal"
  194.       Top             =   2040
  195.       Width           =   480
  196.    End
  197.    Begin VB.CommandButton Operator 
  198.       Caption         =   "="
  199.       Height          =   480
  200.       Index           =   4
  201.       Left            =   1800
  202.       TabIndex        =   16
  203.       ToolTipText     =   "Equals"
  204.       Top             =   2040
  205.       Width           =   480
  206.    End
  207.    Begin VB.CommandButton Percent 
  208.       Caption         =   "%"
  209.       Height          =   480
  210.       Left            =   2280
  211.       TabIndex        =   17
  212.       ToolTipText     =   "Percent"
  213.       Top             =   2040
  214.       Width           =   480
  215.    End
  216.    Begin VB.Label Readout 
  217.       Alignment       =   1  'Right Justify
  218.       BackColor       =   &H00FFFFFF&
  219.       BorderStyle     =   1  'Fixed Single
  220.       Caption         =   "0."
  221.       BeginProperty Font 
  222.          Name            =   "Times New Roman"
  223.          Size            =   12
  224.          Charset         =   0
  225.          Weight          =   700
  226.          Underline       =   0   'False
  227.          Italic          =   0   'False
  228.          Strikethrough   =   0   'False
  229.       EndProperty
  230.       ForeColor       =   &H00000000&
  231.       Height          =   360
  232.       Left            =   120
  233.       TabIndex        =   19
  234.       Top             =   105
  235.       Width           =   2640
  236.    End
  237. Attribute VB_Name = "Calculator"
  238. Attribute VB_GlobalNameSpace = False
  239. Attribute VB_Creatable = False
  240. Attribute VB_PredeclaredId = True
  241. Attribute VB_Exposed = False
  242. Option Explicit
  243. Dim Op1, Op2                ' Previously input operand.
  244. Dim DecimalFlag As Integer  ' Decimal point present yet?
  245. Dim NumOps As Integer       ' Number of operands.
  246. Dim LastInput               ' Indicate type of last keypress event.
  247. Dim OpFlag                  ' Indicate pending operation.
  248. Dim TempReadout
  249. ' Click event procedure for C (cancel) key.
  250. ' Reset the display and initializes variables.
  251. Private Sub Cancel_Click()
  252.     Readout = Format(0, "0.")
  253.     Op1 = 0
  254.     Op2 = 0
  255.     Form_Load
  256. End Sub
  257. ' Click event procedure for CE (cancel entry) key.
  258. Private Sub CancelEntry_Click()
  259.     Readout = Format(0, "0.")
  260.     DecimalFlag = False
  261.     LastInput = "CE"
  262. End Sub
  263. ' Click event procedure for decimal point (.) key.
  264. ' If last keypress was an operator, initialize
  265. ' readout to "0." Otherwise, append a decimal
  266. ' point to the display.
  267. Private Sub Decimal_Click()
  268.     If LastInput = "NEG" Then
  269.         Readout = Format(0, "-0.")
  270.     ElseIf LastInput <> "NUMS" Then
  271.         Readout = Format(0, "0.")
  272.     End If
  273.     DecimalFlag = True
  274.     LastInput = "NUMS"
  275. End Sub
  276. ' Initialization routine for the form.
  277. ' Set all variables to initial values.
  278. Private Sub Form_Load()
  279.     DecimalFlag = False
  280.     NumOps = 0
  281.     LastInput = "NONE"
  282.     OpFlag = " "
  283.     Readout = Format(0, "0.")
  284.     'Decimal.Caption = Format(0, ".")
  285. End Sub
  286. ' Click event procedure for number keys (0-9).
  287. ' Append new number to the number in the display.
  288. Private Sub Number_Click(Index As Integer)
  289.     If LastInput <> "NUMS" Then
  290.         Readout = Format(0, ".")
  291.         DecimalFlag = False
  292.     End If
  293.     If DecimalFlag Then
  294.         Readout = Readout + Number(Index).Caption
  295.     Else
  296.         Readout = Left(Readout, InStr(Readout, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
  297.     End If
  298.     If LastInput = "NEG" Then Readout = "-" & Readout
  299.     LastInput = "NUMS"
  300. End Sub
  301. ' Click event procedure for operator keys (+, -, x, /, =).
  302. ' If the immediately preceeding keypress was part of a
  303. ' number, increments NumOps. If one operand is present,
  304. ' set Op1. If two are present, set Op1 equal to the
  305. ' result of the operation on Op1 and the current
  306. ' input string, and display the result.
  307. Private Sub Operator_Click(Index As Integer)
  308.     TempReadout = Readout
  309.     If LastInput = "NUMS" Then
  310.         NumOps = NumOps + 1
  311.     End If
  312.     Select Case NumOps
  313.         Case 0
  314.         If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  315.             Readout = "-" & Readout
  316.             LastInput = "NEG"
  317.         End If
  318.         Case 1
  319.         Op1 = Readout
  320.         If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  321.             Readout = "-"
  322.             LastInput = "NEG"
  323.         End If
  324.         Case 2
  325.         Op2 = TempReadout
  326.         Select Case OpFlag
  327.             Case "+"
  328.                 Op1 = CDbl(Op1) + CDbl(Op2)
  329.             Case "-"
  330.                 Op1 = CDbl(Op1) - CDbl(Op2)
  331.             Case "X"
  332.                 Op1 = CDbl(Op1) * CDbl(Op2)
  333.             Case "/"
  334.                 If Op2 = 0 Then
  335.                    MsgBox "Can't divide by zero", 48, "Calculator"
  336.                 Else
  337.                    Op1 = CDbl(Op1) / CDbl(Op2)
  338.                 End If
  339.             Case "="
  340.                 Op1 = CDbl(Op2)
  341.             Case "%"
  342.                 Op1 = CDbl(Op1) * CDbl(Op2)
  343.             End Select
  344.         Readout = Op1
  345.         NumOps = 1
  346.     End Select
  347.     If LastInput <> "NEG" Then
  348.         LastInput = "OPS"
  349.         OpFlag = Operator(Index).Caption
  350.     End If
  351. End Sub
  352. ' Click event procedure for percent key (%).
  353. ' Compute and display a percentage of the first operand.
  354. Private Sub Percent_Click()
  355.     Readout = Readout / 100
  356.     LastInput = "Ops"
  357.     OpFlag = "%"
  358.     NumOps = NumOps + 1
  359.     DecimalFlag = True
  360. End Sub
  361.